package tools;

import core.ProxyConnection;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Vector;
import tools.icq.spam.UinChild;


/**
 *
 * @author dcrm
 */

public class AddFucLib {

    /**
     *
     * @param fileName - File proxy list
     * @param separator - ";"
     * @return Collection Proxy/Port/Lofin/Pwd
     */
    public static Vector<ProxyConnection> fillProxyList(String fileName, String separator)
    {
        Vector<ProxyConnection> pCon = new Vector<ProxyConnection>();
        try
        {
            FileInputStream inputStream = new FileInputStream(fileName);
            DataInputStream dataStream = new DataInputStream(inputStream);
            BufferedReader reader = new BufferedReader(new InputStreamReader(dataStream));
            String tmpLine=""; String[] tmpArr; String[] tmpArr0;
            while ((tmpLine=reader.readLine())!=null)
            {
                tmpArr=tmpLine.split(separator);
                if (tmpArr.length>0) {tmpArr0=tmpArr[0].split(":"); if (tmpArr0.length!=2) continue; } else continue;

                switch (tmpArr.length)
                {
                    case 1: pCon.add(new ProxyConnection(tmpArr0[0], Integer.parseInt(tmpArr0[1]))); break;
                    case 2: pCon.add(new ProxyConnection(tmpArr0[0], Integer.parseInt(tmpArr0[1]), Integer.parseInt(tmpArr[1]))); break;
                    case 3: pCon.add(new ProxyConnection(tmpArr0[0], Integer.parseInt(tmpArr0[1]), tmpArr[1], tmpArr[2])); break;
                    case 4: pCon.add(new ProxyConnection(tmpArr0[0], Integer.parseInt(tmpArr0[1]), tmpArr[1], tmpArr[2], Integer.parseInt(tmpArr[3]))); break;
                    default: break;
                }
            }
            reader.close(); dataStream.close(); inputStream.close();
        } catch (Exception ex) {System.err.print(ex.getMessage());}
        return pCon;
    }

    /**
     *
     * @param fileName File icq list
     * @param separator ";"
     * @return Uin/Pwd/pMail
     */
    public static Vector<UinChild> fillUinList(String fileName, String separator)
    {
        Vector<UinChild> lUin = new Vector<UinChild>();
        try
        {
            FileInputStream inputStream = new FileInputStream(fileName);
            DataInputStream dataStream = new DataInputStream(inputStream);
            BufferedReader reader = new BufferedReader(new InputStreamReader(dataStream));
            String tmpLine=""; String[] tmpArr;
            while ((tmpLine=reader.readLine())!=null)
            {
                tmpArr=tmpLine.split(separator);
                if (tmpArr.length==2)
                { lUin.add(new UinChild(tmpArr[0], tmpArr[1])); }
                if (tmpArr.length==3)
                { lUin.add(new UinChild(tmpArr[0], tmpArr[1], tmpArr[2])); }
            }
            reader.close(); dataStream.close(); inputStream.close();
        } catch (Exception ex) {System.err.print(ex.getMessage());}
        return lUin;
    } 
}
